<?php

namespace App\Modules\Shop;

use Illuminate\Database\Eloquent\Model;

/**
 * Class GoodsList
 * @package App\Modules\Shop
 * @property string $goods_type
 * @property integer $link_id
 * @property integer $price
 * @property integer $sort
 * @property integer $sales_volume
 * @property string $time
 * @property int $visitor
 */
class GoodsList extends Model
{
    const TYPE_PACKAGE = 'package';
    const TYPE_GOOD = 'good';

    protected $fillable = [
        'goods_type',
        'link_id',
        'price',
        'sort',
        'sales_volume',
        'time',
        'visitor',
    ];

    public static function addData($type, $id, $price, $sort, $salesVolume, $time, $visitor)
    {
        return self::query()->firstOrCreate([
            'goods_type' => $type,
            'link_id' => $id,
        ], [
            'price' => $price,
            'sort' => $sort??0,
            'sales_volume' => $salesVolume??0,
            'time' => $time,
            'visitor' => $visitor??0,
        ]);
    }
}
